package com.ourteam.workspace.dao.impl;

import com.ourteam.workspace.dao.IWorkspaceCompilerDAO;
import com.ourteam.workspace.dao.WorkspaceCompiler;
import com.ourteam.workspace.dao.WorkspaceCompilerDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-11-30 18:42:34 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractWorkspaceCompilerDAOJdbcImpl extends AbstractSpringDAO
    implements IWorkspaceCompilerDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        WorkspaceId,
        CompilerName,
        CompilerType,
        CompilerLogo,
        CompileCmd,
        RunCmd,
        DebugCmd,
        CompilerLocation,
        Status,
        Remarks,
        DefaultCompiler
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.WorkspaceId,
        _DataObjectProperty.CompilerName,
        _DataObjectProperty.CompilerType,
        _DataObjectProperty.CompilerLogo,
        _DataObjectProperty.CompileCmd,
        _DataObjectProperty.RunCmd,
        _DataObjectProperty.DebugCmd,
        _DataObjectProperty.CompilerLocation,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.DefaultCompiler
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<WorkspaceCompiler, WorkspaceCompilerDAOQueryBean> daoHelper;

  public AbstractWorkspaceCompilerDAOJdbcImpl() {
    super();
    daoHelper = new DataAccessObjectHelper<WorkspaceCompiler, WorkspaceCompilerDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aWorkspaceCompiler
   * @throws Exception
   */
  public boolean checkIsUnique(WorkspaceCompiler aWorkspaceCompiler) throws Exception {

    if (aWorkspaceCompiler == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aWorkspaceCompiler.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aWorkspaceCompiler
   * @throws Exception
   */
  public void insert(WorkspaceCompiler aWorkspaceCompiler) throws Exception {

    super.doInsert(aWorkspaceCompiler);
  }

  /**
   * Batch Insert Datas
   *
   * @param aWorkspaceCompiler
   * @throws Exception
   */
  public void batchInsert(WorkspaceCompiler[] aWorkspaceCompilers) throws Exception {

    super.doBatchInsert(aWorkspaceCompilers);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(WorkspaceCompilerDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(WorkspaceCompiler aWorkspaceCompiler) throws Exception {

    delete(aWorkspaceCompiler.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aWorkspaceCompiler
   * @throws Exception
   */
  public void update(WorkspaceCompiler aWorkspaceCompiler) throws Exception {

    if (aWorkspaceCompiler.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aWorkspaceCompiler);

    WorkspaceCompiler tempObj = findById(aWorkspaceCompiler.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aWorkspaceCompiler, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aWorkspaceCompilers[]
   * @throws Exception
   */
  public void batchUpdate(WorkspaceCompiler[] aWorkspaceCompilers) throws Exception {

    super.doBatchUpdate(aWorkspaceCompilers);
  }

  /**
   * Update Data By Condictions
   *
   * @param aWorkspaceCompiler
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(WorkspaceCompiler aWorkspaceCompiler, WorkspaceCompilerDAOQueryBean aQueryBean)
      throws Exception {

    super.doUpdateByQuery(aWorkspaceCompiler, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(WorkspaceCompilerDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(WorkspaceCompiler aWorkspaceCompiler) throws Exception {

    if (aWorkspaceCompiler.getDefaultCompiler() == null) {
      throw new Exception("The WorkspaceCompiler.defaultCompiler value is not allow NULL");
    }

    if (aWorkspaceCompiler.getCompilerName() == null) {
      throw new Exception("The WorkspaceCompiler.compilerName value is not allow NULL");
    }

    if (aWorkspaceCompiler.getCompilerType() == null) {
      throw new Exception("The WorkspaceCompiler.compilerType value is not allow NULL");
    }

    if (aWorkspaceCompiler.getCompilerLogo() == null) {
      throw new Exception("The WorkspaceCompiler.compilerLogo value is not allow NULL");
    }

    if (aWorkspaceCompiler.getCompileCmd() == null) {
      throw new Exception("The WorkspaceCompiler.compileCmd value is not allow NULL");
    }

    if (aWorkspaceCompiler.getRunCmd() == null) {
      throw new Exception("The WorkspaceCompiler.runCmd value is not allow NULL");
    }

    if (aWorkspaceCompiler.getDebugCmd() == null) {
      throw new Exception("The WorkspaceCompiler.debugCmd value is not allow NULL");
    }

    if (aWorkspaceCompiler.getCompilerLocation() == null) {
      throw new Exception("The WorkspaceCompiler.compilerLocation value is not allow NULL");
    }

    if (aWorkspaceCompiler.getStatus() == null) {
      throw new Exception("The WorkspaceCompiler.status value is not allow NULL");
    }

    if (aWorkspaceCompiler.getRemarks() == null) {
      throw new Exception("The WorkspaceCompiler.remarks value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public WorkspaceCompiler findById(final long id) throws Exception {

    WorkspaceCompilerDAOQueryBean queryBean = new WorkspaceCompilerDAOQueryBean();

    WorkspaceCompilerDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    WorkspaceCompiler[] WorkspaceCompilers = query(queryBean);

    if (WorkspaceCompilers.length == 0) {
      return null;
    } else {
      return WorkspaceCompilers[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return WorkspaceCompiler[]
   * @throws Exception
   */
  public WorkspaceCompiler[] query(WorkspaceCompilerDAOQueryBean queryBean) throws Exception {

    List result = super.doQuery(queryBean, new JdbcWorkspaceCompilerRowMapper());

    return (WorkspaceCompiler[]) result.toArray(new WorkspaceCompiler[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(WorkspaceCompilerDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(WorkspaceCompilerDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      WorkspaceCompiler[] aWorkspaceCompilers, WorkspaceCompilerDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aWorkspaceCompilers, queryBean);
  }

  public void synchronize(
      WorkspaceCompiler[] aWorkspaceCompilers,
      WorkspaceCompilerDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<WorkspaceCompiler> callBack)
      throws Exception {
    daoHelper.synchronize(aWorkspaceCompilers, queryBean, callBack);
  }

  public static class JdbcWorkspaceCompilerRowMapper implements RowMapper<WorkspaceCompiler> {

    public WorkspaceCompiler mapRow(ResultSet resultSet, int arg1) throws SQLException {
      WorkspaceCompiler object = new WorkspaceCompiler();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object workspaceId = null;

        workspaceId = resultSet.getObject(columnIndex++);

        object.setWorkspaceIdNull(resultSet.getBoolean(columnIndex++));

        if (workspaceId != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceId, workspaceId);
        }

        Object compilerName = null;

        compilerName = resultSet.getObject(columnIndex++);

        object.setCompilerNameNull(resultSet.getBoolean(columnIndex++));

        if (compilerName != null) {

          setBeanValue(object, _DataObjectProperty.CompilerName, compilerName);
        }

        Object compilerType = null;

        compilerType = resultSet.getObject(columnIndex++);

        object.setCompilerTypeNull(resultSet.getBoolean(columnIndex++));

        if (compilerType != null) {

          setBeanValue(object, _DataObjectProperty.CompilerType, compilerType);
        }

        Object compilerLogo = null;

        compilerLogo = resultSet.getObject(columnIndex++);

        object.setCompilerLogoNull(resultSet.getBoolean(columnIndex++));

        if (compilerLogo != null) {

          setBeanValue(object, _DataObjectProperty.CompilerLogo, compilerLogo);
        }

        Object compileCmd = null;

        compileCmd = resultSet.getObject(columnIndex++);

        object.setCompileCmdNull(resultSet.getBoolean(columnIndex++));

        if (compileCmd != null) {

          setBeanValue(object, _DataObjectProperty.CompileCmd, compileCmd);
        }

        Object runCmd = null;

        runCmd = resultSet.getObject(columnIndex++);

        object.setRunCmdNull(resultSet.getBoolean(columnIndex++));

        if (runCmd != null) {

          setBeanValue(object, _DataObjectProperty.RunCmd, runCmd);
        }

        Object debugCmd = null;

        debugCmd = resultSet.getObject(columnIndex++);

        object.setDebugCmdNull(resultSet.getBoolean(columnIndex++));

        if (debugCmd != null) {

          setBeanValue(object, _DataObjectProperty.DebugCmd, debugCmd);
        }

        Object compilerLocation = null;

        compilerLocation = resultSet.getObject(columnIndex++);

        object.setCompilerLocationNull(resultSet.getBoolean(columnIndex++));

        if (compilerLocation != null) {

          setBeanValue(object, _DataObjectProperty.CompilerLocation, compilerLocation);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object defaultCompiler = null;

        defaultCompiler = resultSet.getObject(columnIndex++);

        object.setDefaultCompilerNull(resultSet.getBoolean(columnIndex++));

        if (defaultCompiler != null) {

          setBeanValue(object, _DataObjectProperty.DefaultCompiler, defaultCompiler);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
